<html>
<head><meta charset="utf-8"><title>unused-lifetime-error · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unused-lifetime-error.html">unused-lifetime-error</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239710977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unused-lifetime-error/near/239710977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ThatsNoMoon <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unused-lifetime-error.html#239710977">(May 21 2021 at 07:58)</a>:</h4>
<p>I'm curious, why <em>is</em> something like <code>struct Foo&lt;'a&gt;</code> illegal? my first thought was that rust can't determine the variance of a type with respect to an unused lifetime parameter, is that all? is it just a "this should never be what you want" sort of lint? someone tried to write something like <code>struct Foo&lt;'a, T = &amp;'a str&gt;(T);</code> which prompted my wondering</p>



<a name="239717472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unused-lifetime-error/near/239717472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kestrer <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unused-lifetime-error.html#239717472">(May 21 2021 at 08:52)</a>:</h4>
<p>I think it is just to do with variance. Const generics unlike lifetime and type parameters don't need to be used in struct bodies because they don't have variance. It seems that Rust could actually allow it, but intentionally didn't because it was a footgun. <a href="https://doc.rust-lang.org/nomicon/phantom-data.html">The Nomicon's page on <code>PhantomData</code></a> says:</p>
<blockquote>
<p>However because <code>'a</code> is unused within the struct's body, it's unbounded. Because of the troubles this has historically caused, unbounded lifetimes and types are forbidden in struct definitions.</p>
</blockquote>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>